<?php /** 修改用户状态信息 api **/
require_once '../../config/req.conf.php';
require_once '../../utils/CommonMethods.php';
require_once '../../utils/VerifyFormData.php';
require_once '../../utils/DBUtils.php';

/* 1. token认证和角色权限校验 */
$headers = apache_request_headers(); // 请求头信息获取
$info = VerifyFormData::verifyRole($headers['Authorization'], "root");
if( CommonMethods::isEmpty($info) ){
    RespJson::fail("没有访问权限");
    return;
}

/* 2. 数据校验 */
if( !VerifyFormData::isEmptyAndEscape($_POST) ) return;
DBUtils::init();
$has = DBUtils::queryOne(DBUtils::getSql("php_user")->where("id = {$_POST['id']}")->select());
if( CommonMethods::isEmpty($has) ){
    RespJson::fail("不存在该用户");
    return;
}

/* 3. 进行状态信的修改 */
$success = DBUtils::execute(DBUtils::getSql("php_user")
    ->set("status = 0")
    ->where("id = {$_POST['id']}")
    ->update());
if( $success ){
    RespJson::success();
    return;
}else{
    RespJson::fail("操作失败请重试");
    return;
}
